package com.sky.service.impl;


import com.sky.result.Result;
import com.sky.service.UploadService;
import org.example.aliyun.AliyunOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class UploadServiceImpl implements UploadService {
    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;
    @Override
    public Result<String> upload(MultipartFile file) throws Exception {
        // 拿到上传的文件的后缀
        String originalFilename = file.getOriginalFilename();
        String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
        // 拿到上传的文件的字节数组
        byte[] bytes = file.getBytes();
        String upload = aliyunOSSUtils.upload(bytes, extName);
        return Result.success(upload);
    }
}
